package com.lbd.util;

import java.io.IOException;

/**
 * Created by WangYajie on 2016/9/21.
 */
public class VerificationCode {
   /* public static String writeImg(OutputStream out, int length) throws IOException {
        ConfigurableCaptchaService cs = new ConfigurableCaptchaService();
        RandomWordFactory wordFactory = new RandomWordFactory();
        wordFactory.setMaxLength(length);
        wordFactory.setMinLength(length);
        cs.setWordFactory(wordFactory);
        //cs.setColorFactory(new SingleColorFactory(new Color(15, 23, 170)));
        RandomColorFactory randomColorFactory = new RandomColorFactory();
        randomColorFactory.setMax(new Color(255, 200, 255));
        randomColorFactory.setMin(new Color(1, 3, 254));
        cs.setColorFactory(randomColorFactory);
        switch (new Random().nextInt(5)) {
            case 0:
                cs.setFilterFactory(new CurvesRippleFilterFactory(cs.getColorFactory()));
                break;
            case 1:
                cs.setFilterFactory(new MarbleRippleFilterFactory());
                break;
            case 2:
                cs.setFilterFactory(new DoubleRippleFilterFactory());
                break;
            case 3:
                cs.setFilterFactory(new WobbleRippleFilterFactory());
                break;
            case 4:
                cs.setFilterFactory(new DiffuseRippleFilterFactory());
                break;
        }
        String challenge = EncoderHelper.getChallangeAndWriteImage(cs, "png", out);
        out.flush();
        return challenge;
    }

    *//**
     * 返回base64
     *
     * @param length 图片验证码长度
     * @return
     * @throws IOException
     *//*
    public static ConfigurableCaptchaService writeImg(int length) throws IOException {
        ConfigurableCaptchaService cs = new ConfigurableCaptchaService();
        RandomWordFactory wordFactory = new RandomWordFactory();
        wordFactory.setMaxLength(length);
        wordFactory.setMinLength(length);
        cs.setWordFactory(wordFactory);
        //cs.setColorFactory(new SingleColorFactory(new Color(15, 23, 170)));
        RandomColorFactory randomColorFactory = new RandomColorFactory();
        randomColorFactory.setMax(new Color(255, 200, 255));
        randomColorFactory.setMin(new Color(1, 3, 254));
        cs.setColorFactory(randomColorFactory);
        switch (new Random().nextInt(5)) {
            case 0:
                cs.setFilterFactory(new CurvesRippleFilterFactory(cs.getColorFactory()));
                break;
            case 1:
                cs.setFilterFactory(new MarbleRippleFilterFactory());
                break;
            case 2:
                cs.setFilterFactory(new DoubleRippleFilterFactory());
                break;
            case 3:
                cs.setFilterFactory(new WobbleRippleFilterFactory());
                break;
            case 4:
                cs.setFilterFactory(new DiffuseRippleFilterFactory());
                break;
        }
        return  cs;

    }*/

}
